class Model {
	constructor(options) {
		this._model = options.model;
		this._attributes = options.attributes;
		this._obj=Cesium.Model.fromGltf(options.model)
	}
	get id(){
		return this._model.id;
	}
	get obj(){
		return this._obj;
	}
	set model(model) {
		this._model = model;
	}
	get model() {
		return this._model;
	}
	set attributes(attributes) {
		this._attributes = attributes;
	}
	get attributes() {
		return this._attributes;
	}
	setAttribute(key, value) {
		this._attributes[key]=value;
	}
	removeAttribute(key) {
		if (Cesium.defined(this._attributes[key])) {
			delete this._attributes[key]
		}
	}
	get location(){
		return this._model.location;
	}
	set location(location){
		if(Cesium.defined(location.x)){
			this._model.location.x=location.x;
		}
		if(Cesium.defined(location.y)){
			this._model.location.y=location.y;
		}
		if(Cesium.defined(location.z)){
			this._model.location.z=location.z;
		}
		setMatrix();
	}
	get rotation(){
		return this._model.rotation;
	}
	set rotation(rotation){
		if(Cesium.defined(rotation.heading)){
			this._model.rotation.heading=rotation.heading;
		}
		if(Cesium.defined(rotation.pitch)){
			this._model.rotation.pitch=rotation.pitch;
		}
		if(Cesium.defined(rotation.roll)){
			this._model.rotation.roll=rotation.roll;
		}
		setMatrix();
	}
	setMatrix(){
	   var transformPosition =Cesium.Cartesian3.fromDegrees(this._model.location.x*1, this._model.location.y*1,this._model.location.z*1);
	   var matrix = Cesium.Transforms.eastNorthUpToFixedFrame(transformPosition);
	   var scale = Cesium.Matrix4.fromUniformScale(Cesium.defaultValue(this._model.scale,0));
	   Cesium.Matrix4.multiply(matrix, scale, matrix);
	   var rotationX = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(Cesium.defaultValue(this._model.rotation.pitch,0)));
	   var rotationY = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(Cesium.defaultValue(this._model.rotation.heading,0)));
	   var rotationZ = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(Cesium.defaultValue(this._model.rotation.roll,0)));
	   var rotationTranslationX = Cesium.Matrix4.fromRotationTranslation(rotationX);
	   var rotationTranslationY = Cesium.Matrix4.fromRotationTranslation(rotationY);
	   var rotationTranslationZ = Cesium.Matrix4.fromRotationTranslation(rotationZ);
	   Cesium.Matrix4.multiply(matrix, rotationTranslationX, matrix);
	   Cesium.Matrix4.multiply(matrix, rotationTranslationY, matrix);
	   Cesium.Matrix4.multiply(matrix, rotationTranslationZ, matrix);
	  this.obj.modelMatrix=matrix;
	}
	
	/**
	 * @description 显示
	 * @param {Object} show
	 */
	set show(show){
		this._model.show=show;
		this.obj.show=show;
	}
	get show(){
		return this._model.show;
	}
	
	/**
	 * @@description 获取高亮参数
	 */
	get Highlight(){
		return this._model.highlight;
	}
	/**
	 * @description  设置高亮
	 * @param {Object} highlight{
		 type:0-轮廓 1-颜色 2-all
		 silhouetteColor:轮廓颜色,
		 silhouetteSize:轮廓大小,
		 color:颜色
	 }
	 */
	setHighlight(highlight){
		this._model.highlight=Cesium.defaultValue(this._model.highlight,{});
		this._model.highlight.type=Cesium.defaultValue(highlight.type,2);
		if(Cesium.defined(highlight.silhouetteColor)){
			if(highlight.silhouetteColor instanceof Cesium.Color){
				this._model.highlight.silhouetteColor=highlight.silhouetteColor
			}else{
				this._model.highlight.silhouetteColor=Cesium.Color.fromCssColorString(highlight.silhouetteColor)
			}
			this._model.highlight.silhouetteSize=Cesium.defaultValue(highlight.silhouetteSize,1);
		}
		
		if(Cesium.defined(highlight.color)){
			if(highlight.color instanceof Cesium.Color){
				this._model.highlight.color=highlight.color
			}else{
				this._model.highlight.color=Cesium.Color.fromCssColorString(highlight.color)
			}
		}
		//轮廓
		if(0==highlight.type){
			this._obj.silhouetteColor==Cesium.defaultValue(this._model.highlight.silhouetteColor,Cesium.Color.RED);
			this._obj.silhouetteSize==Cesium.defaultValue(this._model.highlight.silhouetteSize,1);
		}else if(1==highlight.type){
			this._obj.color==Cesium.defaultValue(this._model.highlight.color,Cesium.Color.RED);
		}else{
			this._obj.color==Cesium.defaultValue(this._model.highlight.color,Cesium.Color.RED);
			this._obj.silhouetteColor==Cesium.defaultValue(this._model.highlight.silhouetteColor,Cesium.Color.RED);
			this._obj.silhouetteSize==Cesium.defaultValue(this._model.highlight.silhouetteSize,1);
		}
		return this._model.highlight;
	}
	
	/**
	 * @@description 停止高亮
	 */
	stopHighlight(){
		this._obj.silhouetteColor==Cesium.defaultValue(this._model.silhouetteColor,Cesium.Color.RED);
		this._obj.silhouetteSize==Cesium.defaultValue(this._model.silhouetteSize,0);
		this._obj.color==Cesium.defaultValue(this._model.color,Cesium.Color.WHITE);
	}
	
	/**
	 * @description 缩放
	 * @param {Number} scale
	 */
	set scale(scale){
		this._model.scale=scale;
		this.obj.scale=scale;
	}
	get scale(){
		return this._model.scale
	}
	/**
	 * @description 最小像素
	 * @param {Number} minimumPixelSize
	 */
	set minimumPixelSize(minimumPixelSize){
		this._model.minimumPixelSize=minimumPixelSize;
		this.obj.minimumPixelSize=minimumPixelSize;
	}
	get minimumPixelSize(){
		return this._model.minimumPixelSize
	}
	
	/**
	 * @description 最大比例
	 * @param {Number} maximumScale
	 */
	set maximumScale(maximumScale){
		this._model.maximumScale=maximumScale;
		this.obj.maximumScale=maximumScale;
	}
	get maximumScale(){
		return this._model.maximumScale
	}
	
	/**
	 * @description 拾取模型
	 * @param {Boolean} allowPicking
	 */
	set allowPicking(allowPicking){
		this._model.allowPicking=allowPicking;
		this.obj.allowPicking=allowPicking;
	}
	get allowPicking(){
		return this._model.allowPicking
	}
	
	/**
	 * @description 确定在加载模型后纹理是否可以继续流入
	 * @param {Boolean} incrementallyLoadTextures
	 */
	set incrementallyLoadTextures(incrementallyLoadTextures){
		this._model.incrementallyLoadTextures=incrementallyLoadTextures;
		this.obj.incrementallyLoadTextures=incrementallyLoadTextures;
	}
	get incrementallyLoadTextures(){
		return this._model.incrementallyLoadTextures
	}
	
	/**
	 * @description 确定是否在所有glTF文件加载完成后将模型WebGL资源创建分散在几个帧上还是阻止直到完成。
	 * @param {Boolean} asynchronous
	 */
	set asynchronous(asynchronous){
		this._model.asynchronous=asynchronous;
		this.obj.asynchronous=asynchronous;
	}
	get asynchronous(){
		return this._model.asynchronous
	}
	
	/**
	 * @description 确定模型的动画是否应在未指定关键帧的帧上保持姿势
	 * @param {Boolean} clampAnimations
	 */
	set clampAnimations(clampAnimations){
		this._model.clampAnimations=clampAnimations;
		this.obj.clampAnimations=clampAnimations;
	}
	get clampAnimations(){
		return this._model.clampAnimations
	}
	
	/**
	 * @description 确定模型是投射还是接收来自每个光源的阴影
	 * @param {Number} shadows{
		 0- 对象不投射或接收阴影
		 1- 对象投射并接收阴影。
		 2- 对象仅投射阴影
		 3- 对象仅接收阴影
	 }
	 */
	set shadows(shadows){
		this._model.shadows=shadows;
		this.obj.shadows=shadows;
	}
	get shadows(){
		return this._model.shadows
	}
	
	/**
	 * @description 绘制边界球
	 * @param {Boolean} debugShowBoundingVolume
	 */
	set debugShowBoundingVolume(debugShowBoundingVolume){
		this._model.debugShowBoundingVolume=debugShowBoundingVolume;
		this.obj.debugShowBoundingVolume=debugShowBoundingVolume;
	}
	get debugShowBoundingVolume(){
		return this._model.debugShowBoundingVolume
	}
	
	/**
	 * @description 线框中绘制模型
	 * @param {Boolean} debugWireframe
	 */
	set debugWireframe(debugWireframe){
		this._model.debugWireframe=debugWireframe;
		this.obj.debugWireframe=debugWireframe;
	}
	get debugWireframe(){
		return this._model.debugWireframe
	}
	
	/**
	 * @description 线框中绘制模型
	 * @param {Number} heightReference{
		 0-绝对位置
		 1-贴地(位置固定在地形)
		 2-高度是指地形上方的高度
	 }
	 */
	set heightReference(heightReference){
		this._model.heightReference=heightReference;
		this.obj.heightReference=heightReference;
	}
	get heightReference(){
		return this._model.heightReference
	}
	
	/**
	 * @description 对于使用height reference属性的模型必须传递
	 * @param {	Scene} scene
	 */
	set scene(scene){
		this._model.scene=scene;
		this.obj.scene=scene;
	}
	get scene(){
		return this._model.scene
	}
	
	/**
	 * @description 指定将在距相机的距离处显示此模型。
	 * @param {	DistanceDisplayCondition} {
		 near:可见物体的间隔中的最小距离,
		 far:在物体可见的间隔中最大的距离,
	 }
	 */
	set distanceDisplayCondition(distanceDisplayCondition){
		this._model.distanceDisplayCondition=Cesium.defaultValue(this._model.distanceDisplayCondition,{});
		this._model.distanceDisplayCondition.near=Cesium.defaultValue(distanceDisplayCondition.near,0.0);
		this._model.distanceDisplayCondition.far=Cesium.defaultValue(distanceDisplayCondition.far,Cesium.Number.MAX_VALUE);
		this.obj.distanceDisplayCondition=new Cesium.DistanceDisplayCondition(this._model.distanceDisplayCondition.near,this._model.distanceDisplayCondition.far);
	}
	get distanceDisplayCondition(){
		return this._model.distanceDisplayCondition
	}
	
	/**
	 * @description 模型的渲染颜色混合的颜色
	 * @param {Color/Strng} color
	 */
	set color(color){
		this._model.color=color;
		if(color instanceof Cesium.Color){
			this.obj.color=Cesium.Color.fromCssColorString(color)
		}else{
			this.obj.color=Cesium.Color.fromCssColorString(color)
		}
	}
	get color(){
		return this._model.color
	}
	
	/**
	 * @description 轮廓颜色
	 * @param {Color/Strng} color
	 */
	set silhouetteColor(silhouetteColor){
		this._model.silhouetteColor=silhouetteColor;
		if(silhouetteColor instanceof Cesium.Color){
			this.obj.silhouetteColor=Cesium.Color.fromCssColorString(silhouetteColor)
		}else{
			this.obj.silhouetteColor=Cesium.Color.fromCssColorString(silhouetteColor)
		}
	}
	get silhouetteColor(){
		return this._model.silhouetteColor
	}
	
	/**
	 * @description 轮廓的大小
	 * @param {Number} silhouetteSize
	 */
	set silhouetteSize(silhouetteSize){
		this._model.silhouetteSize=silhouetteSize;
		this.obj.silhouetteSize=silhouetteSize
	}
	get silhouetteSize(){
		return this._model.silhouetteSize
	}
	
	/**
	 * @description 有选择地禁用渲染模型
	 * @param {Object} clippingPlanes
	 */
	set clippingPlanes(clippingPlanes){
		this._model.clippingPlanes=clippingPlanes;
		this.obj.clippingPlanes=clippingPlanes
	}
	get clippingPlanes(){
		return this._model.clippingPlanes
	}
	
	 //flicker
	
	
}
export {
	Model
}
